<?php

session_start();
include_once '../include/common.php';
require_once '../include/Classes/PHPExcel.php';
$core = new core();
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
if (PHP_SAPI == 'cli') {
    echo json_encode(array('type' => 1, 'msg' => "Có lỗi xảy ra, vui lòng thử lại."));
    die;
}
$zen_order_id = isset($_POST["zen_order_id"]) ? intval($_POST["zen_order_id"]) : 0;
$by_product_customer = isset($_POST["by_product_customer"]) ? intval($_POST["by_product_customer"]) : 0;
$by_order_status = isset($_POST["by_order_status"]) ? intval($_POST["by_order_status"]) : 0;
$by_province = isset($_POST["by_province"]) ? intval($_POST["by_province"]) : 0;
$by_payment = isset($_POST["by_payment"]) ? intval($_POST["by_payment"]) : 0;
$search_text = isset($_POST["search_text"]) ? addslashes(trim($_POST["search_text"])) : '';
$start_time = isset($_POST["start_time"]) ? addslashes(trim($_POST["start_time"])) : '';
$end_time = isset($_POST["end_time"]) ? addslashes(trim($_POST["end_time"])) : '';
$hidden_group_1 = isset($_POST["hidden_group_1"]) ? intval($_POST["hidden_group_1"]) : 0;
$hidden_group_2 = isset($_POST["hidden_group_2"]) ? intval($_POST["hidden_group_2"]) : 0;
$hidden_group_3 = isset($_POST["hidden_group_3"]) ? intval($_POST["hidden_group_3"]) : 0;
$hidden_group_4 = isset($_POST["hidden_group_4"]) ? intval($_POST["hidden_group_4"]) : 0;
$customer_order_by = '';
if ($by_product_customer == 0 && $by_order_status == 0 && $by_province == 0 && $by_payment == 0 && $search_text != "") {
    echo json_encode(array('type' => 1, 'msg' => "Vui lòng chọn 1 trong 4 sự lựa chọn để sắp xếp!"));
    die;
}
if ($start_time != "" && $end_time != "") {
    if (strtotime($end_time) <= strtotime($start_time)) {
        echo json_encode(array('type' => 1, 'msg' => "Bạn phải chọn thời gian kết thúc lớn hơn thời gian bắt đầu!"));
        die;
    }
}
$old_start_time = '';
$old_end_time = '';
if ($start_time != "") {
    $old_start_time = date("d-m-Y H:i:s", strtotime($start_time));
    $start_time = $core->changeDateMysqlToCompare(date("Y-m-d H:i:s", strtotime($start_time)));
}
if ($end_time != "") {
    $old_end_time = date("d-m-Y H:i:s", strtotime($end_time));
    $end_time = $core->changeDateMysqlToCompare(date("Y-m-d H:i:s", strtotime($end_time)));
}

$where = '';
if ($by_order_status > 0) {
    switch ($by_order_status) {
        case 1:
            //store
            $where.='order_status=0';
            if ($start_time != "") {
                $where.=' AND store_date >="' . $start_time . '"';
            }
            if ($end_time != "") {
                $where.=' AND store_date<"' . $end_time . '"';
            }
            $customer_order_by .= "store_date asc";
            break;
        case 2:
            //online
            $where.='order_status=1';
            if ($start_time != "") {
                $where.=' AND online_date >="' . $start_time . '"';
            }
            if ($end_time != "") {
                $where.=' AND online_date<"' . $end_time . '"';
            }
            $customer_order_by .= "online_date asc";
            break;
        case 3:
            //hàng có sẵn
            $where.='order_status=2';
            break;
        case 4:
            //đã nhận hàng
            $where.='order_status=3';
            if ($start_time != "") {
                $where.=' AND received_date >="' . $start_time . '"';
            }
            if ($end_time != "") {
                $where.=' AND received_date<"' . $end_time . '"';
            }
            $customer_order_by .= "received_date asc";
            break;
        case 5:
            //đang shipping
            $where.='order_status=4';
            break;
        case 6:
            //khách đã nhận
            $where.='order_status=5';
            if ($start_time != "") {
                $where.=' AND saled_date >="' . $start_time . '"';
            }
            if ($end_time != "") {
                $where.=' AND saled_date<"' . $end_time . '"';
            }
            $customer_order_by .= "saled_date asc";
            break;
        case 7:
            //hết hàng
            $where.='order_status=6';
            break;
        case 8:
            //ORDER
            $where.='order_status=7';
            if ($start_time != "") {
                $where.=' AND customer_order_date >="' . $start_time . '"';
            }
            if ($end_time != "") {
                $where.=' AND customer_order_date <"' . $end_time . '"';
            }
            $customer_order_by .= "customer_order_date asc";
            break;
        case 9:
            //chưa chắc chắn
            $where.='order_status=8';
            break;
    }
} else {
    if ($start_time != "") {
        if ($where == '') {
            $where.='(store_date >="' . $start_time . '" OR online_date >="' . $start_time . '" OR received_date >="' . $start_time . '"
            OR saled_date >="' . $start_time . '" OR customer_order_date >="' . $start_time . '")';
        } else {
            $where.=' AND (store_date >="' . $start_time . '" OR online_date >="' . $start_time . '" OR received_date >="' . $start_time . '"
            OR saled_date >="' . $start_time . '" OR customer_order_date >="' . $start_time . '")';
        }
    }
    if ($end_time != "") {
        if ($where == '') {
            $where.='(store_date<"' . $end_time . '" OR online_date<"' . $end_time . '" OR received_date<"' . $end_time . '" 
                  OR saled_date<"' . $end_time . '" OR customer_order_date <"' . $end_time . '")';
        } else {
            $where.=' AND (store_date<"' . $end_time . '" OR online_date<"' . $end_time . '" OR received_date<"' . $end_time . '" 
                  OR saled_date<"' . $end_time . '" OR customer_order_date <"' . $end_time . '")';
        }
    }
}
if ($customer_order_by != "") {
    //ORDER: sắp xếp ngày đặt mua tăng dần
    if ($by_product_customer == 1) {
        $customer_order_by .= ", product_code asc";
    } elseif ($by_product_customer == 2) {
        $customer_order_by .= ", facebook_name asc";
    }
} else {
    if ($by_product_customer == 1) {
        $customer_order_by .= "product_code asc";
    } elseif ($by_product_customer == 2) {
        $customer_order_by .= "facebook_name asc";
    }
}
if ($by_payment > 0) {
    switch ($by_payment) {
        case 1:
            //thanh toán hết
            if ($where == '') {
                $where.='total_current_money=0';
            } else {
                $where.=' AND total_current_money=0';
            }
            break;
        case 2:
            //thanh toán thừa
            if ($where == '') {
                $where.='total_current_money > 0';
            } else {
                $where.=' AND total_current_money > 0';
            }
            break;
        case 3:
            //thanh toán thiếu
            if ($where == '') {
                $where.='total_current_money < 0';
            } else {
                $where.=' AND total_current_money < 0';
            }
            break;
        case 4:
            //đã cọc
            if ($where == '') {
                $where.='total_payment > 0';
            } else {
                $where.=' AND total_payment > 0';
            }
            break;
        case 5:
            //chưa thanh toán
            if ($where == '') {
                $where.='total_payment = 0';
            } else {
                $where.=' AND total_payment = 0';
            }
            break;
    }
}
if ($search_text !== "") {
    if ($by_product_customer == 1) {
        if ($where == '') {
            $where.="product_code LIKE '%" . $search_text . "%'";
        } else {
            $where.=" AND product_code LIKE '%" . $search_text . "%'";
        }
    } elseif ($by_product_customer == 2) {
        if ($where == '') {
            $where.="facebook_name LIKE '%" . $search_text . "%'";
        } else {
            $where.=" AND facebook_name LIKE '%" . $search_text . "%'";
        }
    }
}
if ($by_province > 0) {
    switch ($by_province) {
        case 1:
            //tỉnh
            if ($where == '') {
                $where.='province=1';
            } else {
                $where.=' AND province=1';
            }
            break;
        case 2:
            //Hà Nội
            if ($where == '') {
                $where.='province=0';
            } else {
                $where.=' AND province=0';
            }
            break;
    }
}
$zen_order = $core->checkZenOrderByID($zen_order_id);
if ($zen_order) {
    $total_result = array();
    if ($by_order_status > 0 || $by_product_customer == 1) {
        $is_group_customer = 0;
    } else {
        $is_group_customer = 1;
    }
    $load_more = 0;
    $list_customer_order = $core->getListCustomerOrderFilterByCustomer($zen_order_id, $customer_order_by, $where, 1, $load_more, $total_result, 0);
    $html = '';
    if ($list_customer_order) {
        $html.='<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Zen store</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="Charisma, a fully featured, responsive, HTML5, Bootstrap admin template.">
        <meta name="author" content="Muhammad Usman">

        <!-- The styles -->
        <link  href="../css/bootstrap-cerulean.css" rel="stylesheet">
        <style type="text/css">
            body {
                padding-bottom: 40px;
            }
            .sidebar-nav {
                padding: 9px 0;
            }
        </style>
        <link href="../css/bootstrap-responsive.css" rel="stylesheet">
        <link href="../css/charisma-app.css" rel="stylesheet">
        <link href="../css/jquery-ui-1.8.21.custom.css" rel="stylesheet">
        <link href="../css/fullcalendar.css" rel="stylesheet">
        <link href="../css/fullcalendar.print.css" rel="stylesheet"  media="print">
        <link href="../css/chosen.css" rel="stylesheet">
        <link href="../css/uniform.default.css" rel="stylesheet">
        <link href="../css/colorbox.css" rel="stylesheet">
        <link href="../css/jquery.cleditor.css" rel="stylesheet">
        <link href="../css/jquery.noty.css" rel="stylesheet">
        <link href="../css/noty_theme_default.css" rel="stylesheet">
        <link href="../css/elfinder.min.css" rel="stylesheet">
        <link href="../css/elfinder.theme.css" rel="stylesheet">
        <link href="../css/jquery.iphone.toggle.css" rel="stylesheet">
        <link href="../css/opa-icons.css" rel="stylesheet">
        <link href="../css/uploadify.css" rel="stylesheet">

        <!-- The HTML5 shim, for IE6-8 support of HTML5 elements -->
        <!--[if lt IE 9]>
          <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->

        <!-- The fav icon -->
        <link rel="shortcut icon" href="img/favicon.ico">

    </head>

    <body>
        <!-- topbar starts -->
        <div class="navbar">
            <div class="navbar-inner">
                <div class="container-fluid">
                    <a class="btn btn-navbar" data-toggle="collapse" data-target=".top-nav.nav-collapse,.sidebar-nav.nav-collapse">
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </a>



                </div>
            </div>
        </div>
        <!-- topbar ends -->
        <div class="container-fluid">
            <div class="row-fluid">
                <div id="content" class="span12" style="margin-left: 0px;">
                    <div class="row-fluid sortable">		
                        <div class="box span12">
                            <div class="box-header well" data-original-title>
                                <h2><i class="icon-user"></i> Products List</h2>

                            </div>
                            <div class="box-content">';
        $html.='<table class="table table-striped table-bordered bootstrap-datatable datatable">
                        <tr>
                                <th>Thời gian bắt đầu</th>
                                <th>Thời gian kết thúc</th>
                                
                               
                            </tr>
                            <tr>
                                <td>' . $old_start_time . '</td>
                                <td>' . $old_end_time . '</td>
                                
                                
                            </tr>
                    </table>';
        $html.='<table class="table  table-bordered  ">
                                    <thead>
                                        <tr>
                                           <th>STT</th>
                                            <th>Tên FB</th>
                                            <th>Phone</th>
                                            <th>Mã SP</th>
                                            
                                            <th>Size</th>
                                            <th>Số Lượng</th>
                                            <th>Màu</th>
                                            <th>Ảnh</th>
                                            <th>Order status</th>';
        $html.='<th>Thời gian</th>';

                                    $html.='<th>Ghi chú sản phẩm</th>';
        if ($hidden_group_3 == 0) {
                                    $html.=' <th>Giá<br/>(x1000 VNĐ)</th>';
        }
        if ($hidden_group_2 == 0) {
            $html .= '<th>Giá AT</th>';
        }
        if ($hidden_group_1 == 0) {
            $html .= '<th>Giá PT</th>';
        }

         if ($hidden_group_2 == 0) {
            $html .= '<th>Tổng giá AT</th>';
        }
        if ($hidden_group_1 == 0) {
            $html .= '<th>Tổng giá PT</th>';
        }

        if ($hidden_group_3 == 0) {
                                    $html.='<th>Tổng Tiền<br/>(x1000 VNĐ)</th>
                                            <th>Tổng Cọc<br/>(x1000 VNĐ)</th>
                                            <th>Thiếu<br/>(x1000 VNĐ)</th>
                                            <th>Thừa<br/>(x1000 VNĐ)</th>';

        }
         $html.='<th>Ghi chú đơn hàng</th>';
        if ($hidden_group_4 == 0) {
            $html.='<th>Địa chỉ</th>
                                            <th>Tỉnh</th>
                                            <th>Tên thật</th>
                                            <th>Tài khoản bank</th>';
        }
        $html.=' </tr>
                                    </thead>   
                                    <tbody>';
        if ($is_group_customer == 0) {
            //sắp xếp theo ngày ORDER hoặc theo mã sp: không gom nhóm khách được
            $var_count = 0;
            foreach ($list_customer_order as $customer_order) {
                $date_status = '';
                $status = '';
                switch ($customer_order->order_status) {
                    case 0:
                        //store
                        $status.='Store';
                        $date_status = $core->changeDateMysqlToShow($customer_order->store_date);
                        break;
                    case 1:
                        //online
                        $status.='Online';
                        $date_status = $core->changeDateMysqlToShow($customer_order->online_date);
                        break;
                    case 2:
                        //hàng có sẵn
                        $status.='Hàng có sẵn';
                        break;
                    case 3:
                        //đã nhận hàng
                        $status.='Đã nhận hàng';
                        $date_status = $core->changeDateMysqlToShow($customer_order->received_date);
                        break;
                    case 4:
                        //đang shipping
                        $status.='Đang shipping';
                        break;
                    case 5:
                        //khách đã nhận
                        $status.='Khách đã nhận';
                        $date_status = $core->changeDateMysqlToShow($customer_order->saled_date);
                        break;
                    case 6:
                        //hết hàng
                        $status.='Hết hàng';
                        break;
                    case 7:
                        //ORDER
                        $status.='ORDER';
                        $date_status = $core->changeDateMysqlToShow($customer_order->customer_order_date);
                        break;
                    case 8:
                        //chưa chắc chắn
                        $status.='Chưa chắc chắn';
                        break;
                }
                $color_photo_name = $customer_order->product_color . "_" . $customer_order->product_code . "_" . $customer_order->manufacture;
                $color_photo_name = $core->convert_string_friendly($color_photo_name) . ".jpg";
                $path_color_photo = dirname(dirname(__FILE__)) . DS . "photo" . DS . "extra_photo" . DS . "thumb_extra_photo" . DS . $color_photo_name;

                if (file_exists($path_color_photo)) {
                    $src_photo = '../photo/extra_photo/' . $color_photo_name;
                    $src_photo_thumb = '../photo/extra_photo/thumb_extra_photo/' . $color_photo_name;
                } else {
                    $src_photo = '../photo/' . $customer_order->main_photo;
                    $src_photo_thumb = '../photo/thumb_photo/200_' . $customer_order->main_photo;
                }
                $var_count++;
                if ($customer_order->total_current_money > 0) {
                    $excess_cash = number_format($customer_order->total_current_money / 1000);
                    $debit = 0;
                } else {
                    $excess_cash = 0;
                    $debit = number_format($customer_order->total_current_money / 1000);
                }
                $html.='<tr class="tr_' . $customer_order->customer_order_id . '">';
                $html.='<td class="center" >' . $var_count . '</td>';
                $html.='<td class="center" >' . $customer_order->facebook_name . '</td>';

                $html.='<td class="center" >' . $customer_order->phone . '</td>';
                $html.='<td class="center">' . $customer_order->product_code . '</td>';


                $html.='<td class="center">' . $customer_order->product_size . '</td>
                            <td class="center">' . $customer_order->product_num . '</td>
                            <td class="center">' . $customer_order->product_color . '</td>
                            <td class="center"><img rel="' . $src_photo . '" class="photo_product" src="' . $src_photo_thumb . '" width="100px"></td>
                            <td class="center">
                               ' . $status . '</div>
                             </td>';
                $html.='<td class="center">
                               ' . $date_status . '</div>
                             </td>';

                $html.='<td class="center">' . $customer_order->description . '</td>';
                if ($hidden_group_3 == 0) {
                    $html.='<td class="center">' . number_format($customer_order->product_price / 1000) . '</td>';
                }
                if ($hidden_group_2 == 0) {
                    $html.='<td class="center">' . number_format($customer_order->stamp_price) . '</td>';
                }
                if ($hidden_group_1 == 0) {
                    $html.='<td class="center">' . number_format($customer_order->store_price) . '</td>';
                }
                if ($hidden_group_2 == 0) {
                    $html.='<td class="center">' . number_format($customer_order->product_num * $customer_order->stamp_price) . '</td>';
                }
                if ($hidden_group_1 == 0) {
                    $html.='<td class="center">' . number_format($customer_order->product_num * $customer_order->store_price) . '</td>';
                }

                if ($hidden_group_3 == 0) {
                    $html.='<td class="center" id="td_price_' . $customer_order->id . '">' . number_format($customer_order->product_num * $customer_order->product_price / 1000) . '</td>
                            <td class="center" >' . number_format($customer_order->total_payment / 1000) . '</td>
                             <td class="center" ></td>
                            <td class="center" ></td>                           
                              ';
                }
                $html.='<td class="center" >' . $customer_order->order_description . '</td>';
                if ($hidden_group_4 == 0) {
                    $html.=' <td class="center" >' . $customer_order->address . '</td>
                            <td class="center" >';
                    if ($customer_order->province == 1)
                        $html.= "Ở tỉnh";
                    else
                        $html.= "Ở HN";

                    $html.='</td>
                                <td class="center" >' . $customer_order->name . '</td>
                                <td class="center" >' . $customer_order->bank_account . '</td>
                                <td class="center" >
                                </td>';
                }
                $html.='</tr>';
            }
        } else {
            //gom theo khách
            $var_count = 0;
            $customer_order_id = 0;
            foreach ($list_customer_order as $customer_order) {
                $date_status = '';
                $status = '';
                switch ($customer_order->order_status) {
                    case 0:
                        //store
                        $status.='Store';
                        $date_status = $core->changeDateMysqlToShow($customer_order->store_date);
                        break;
                    case 1:
                        //online
                        $status.='Online';
                        $date_status = $core->changeDateMysqlToShow($customer_order->online_date);
                        break;
                    case 2:
                        //hàng có sẵn
                        $status.='Hàng có sẵn';
                        break;
                    case 3:
                        //đã nhận hàng
                        $status.='Đã nhận hàng';
                        $date_status = $core->changeDateMysqlToShow($customer_order->received_date);
                        break;
                    case 4:
                        //đang shipping
                        $status.='Đang shipping';
                        break;
                    case 5:
                        //khách đã nhận
                        $status.='Khách đã nhận';
                        $date_status = $core->changeDateMysqlToShow($customer_order->saled_date);
                        break;
                    case 6:
                        //hết hàng
                        $status.='Hết hàng';
                        break;
                    case 7:
                        //ORDER
                        $status.='ORDER';
                        $date_status = $core->changeDateMysqlToShow($customer_order->customer_order_date);
                        break;
                    case 8:
                        //chưa chắc chắn
                        $status.='Chưa chắc chắn';
                        break;
                }
                $color_photo_name = $customer_order->product_color . "_" . $customer_order->product_code . "_" . $customer_order->manufacture;
                $color_photo_name = $core->convert_string_friendly($color_photo_name) . ".jpg";
                $path_color_photo = dirname(dirname(__FILE__)) . DS . "photo" . DS . "extra_photo" . DS . "thumb_extra_photo" . DS . $color_photo_name;

                if (file_exists($path_color_photo)) {
                    $src_photo = '../photo/extra_photo/' . $color_photo_name;
                    $src_photo_thumb = '../photo/extra_photo/thumb_extra_photo/' . $color_photo_name;
                } else {
                    $src_photo = '../photo/' . $customer_order->main_photo;
                    $src_photo_thumb = '../photo/thumb_photo/200_' . $customer_order->main_photo;
                }
                if ($customer_order_id != $customer_order->customer_order_id) {
                    $var_count++;
                    $customer_order_id = $customer_order->customer_order_id;
                    if ($customer_order->total_current_money > 0) {
                        $excess_cash = number_format($customer_order->total_current_money / 1000);
                        $debit = 0;
                    } else {
                        $excess_cash = 0;
                        $debit = number_format($customer_order->total_current_money / 1000);
                    }
                    $html.='<tr class="tr_' . $customer_order->customer_order_id . '">';
                    $html.='<td class="center" rowspan="' . $customer_order->total_product . '">' . $var_count . '</td>';
                    $html.='<td class="center" rowspan="' . $customer_order->total_product . '">';
                    $html.=$customer_order->facebook_name;
                    $html.='</td>';

                    $html.='<td class="center" rowspan="' . $customer_order->total_product . '">' . $customer_order->phone . '</td>';
                    $html.='<td class="center">' . $customer_order->product_code . '</td>';


                    $html.='<td class="center">' . $customer_order->product_size . '</td>
                            <td class="center">' . $customer_order->product_num . '</td>
                            <td class="center">' . $customer_order->product_color . '</td>
                            <td class="center"><img rel="' . $src_photo . '" class="photo_product" src="' . $src_photo_thumb . '" width="100px"></td>
                            <td class="center">
                               ' . $status . '</div>
                             </td>';
                    $html.='<td class="center">
                               ' . $date_status . '</div>
                             </td>';

                    $html.='<td class="center">' . $customer_order->description . '</td>';
                    if ($hidden_group_3 == 0) {
                        $html.='<td class="center" id="td_price_' . $customer_order->id . '">' . number_format($customer_order->product_price / 1000) . '</td>';
                    }
                    if ($hidden_group_2 == 0) {
                        $html.='<td class="center" >' . number_format($customer_order->stamp_price) . '</td>';
                    }
                    if ($hidden_group_1 == 0) {
                        $html.='<td class="center" >' . number_format($customer_order->store_price) . '</td>';
                    }
                    if ($hidden_group_2 == 0) {
                        $html.='<td class="center"  rowspan="' . $customer_order->total_product . '">' . number_format($customer_order->total_at) . '</td>';
                    }
                    if ($hidden_group_1 == 0) {
                        $html.='<td class="center"  rowspan="' . $customer_order->total_product . '">' . number_format($customer_order->total_pt) . '</td>';
                    }

                    if ($hidden_group_3 == 0) {
                        $html.='<td class="center" id="td_total_price_' . $customer_order->customer_order_id . '" rowspan="' . $customer_order->total_product . '">' . number_format($customer_order->total_order_money / 1000) . '</td>
                            <td class="center"  rowspan="' . $customer_order->total_product . '">' . number_format($customer_order->total_payment / 1000) . '</td>
                             <td class="center" id="td_debit_' . $customer_order->customer_order_id . '" rowspan="' . $customer_order->total_product . '">' . $debit . '</td>
                            <td class="center" id="td_excess_cash_' . $customer_order->customer_order_id . '" rowspan="' . $customer_order->total_product . '">' . $excess_cash . '</td>                           
                           
                             ';
                    }
                    $html.='<td class="center" rowspan="' . $customer_order->total_product . '">' . $customer_order->order_description . '</td>';
                    if ($hidden_group_4 == 0) {
                        $html.=' <td class="center" rowspan="' . $customer_order->total_product . '">' . $customer_order->address . '</td>
                            <td class="center" rowspan="' . $customer_order->total_product . '">';

                        if ($customer_order->province == 1)
                            $html.= "Ở tỉnh";
                        else
                            $html.= "Ở HN";

                        $html.='</td>
                            <td class="center" rowspan="' . $customer_order->total_product . '">' . $customer_order->name . '</td>
                            <td class="center" rowspan="' . $customer_order->total_product . '">' . $customer_order->bank_account . '</td>';
                    }
                    $html.='</tr>';
                } else {

                    $html.=' <tr class="tr_' . $customer_order->customer_order_id . '">';
                    $html.='<td class="center">' . $customer_order->product_code . '</td>';


                    $html.='<td class="center">' . $customer_order->product_size . '</td>
                            <td class="center">' . $customer_order->product_num . '</td>
                            <td class="center">' . $customer_order->product_color . '</td>
                            <td class="center"><img rel="' . $src_photo . '" class="photo_product" src="' . $src_photo_thumb . '" width="100px"></td>
                            <td class="center">
                               ' . $status . '</div>
                             </td>';

                    $html.='<td class="center">
                               ' . $date_status . '</div>
                             </td>';

                    $html.='<td class="center">' . $customer_order->description . '</td>';
                    if ($hidden_group_3 == 0) {
                        $html.='<td class="center" id="td_price_' . $customer_order->id . '">' . number_format($customer_order->product_price / 1000) . '</td>';
                    }
                    if ($hidden_group_2 == 0) {
                        $html.='<td class="center" >' . number_format($customer_order->stamp_price) . '</td>';

                    }
                    if ($hidden_group_1 == 0) {
                        $html.=' <td class="center" >' . number_format($customer_order->store_price) . '</td>';
                    }

                    $html.='</tr>';
                }
            }
        }

        $html.='</tbody>
                                </table>            
                            </div>
                        </div><!--/span-->

                    </div><!--/row-->



                    <!-- content ends -->
                </div><!--/#content.span10-->
            </div><!--/fluid-row-->

            <hr>



        </div><!--/.fluid-container-->

        <!-- external javascript
        ================================================== -->
        <!-- Placed at the end of the document so the pages load faster -->

        <!-- jQuery -->
        <script src="../js/jquery-1.7.2.min.js"></script>
        <!-- jQuery UI -->
        <script src="../js/jquery-ui-1.8.21.custom.min.js"></script>
        <!-- transition / effect library -->
        <script src="../js/bootstrap-transition.js"></script>
        <!-- alert enhancer library -->
        <script src="../js/bootstrap-alert.js"></script>
        <!-- modal / dialog library -->
        <script src="../js/bootstrap-modal.js"></script>
        <!-- custom dropdown library -->
        <script src="../js/bootstrap-dropdown.js"></script>
        <!-- scrolspy library -->
        <script src="../js/bootstrap-scrollspy.js"></script>
        <!-- library for creating tabs -->
        <script src="../js/bootstrap-tab.js"></script>
        <!-- library for advanced tooltip -->
        <script src="../js/bootstrap-tooltip.js"></script>
        <!-- popover effect library -->
        <script src="../js/bootstrap-popover.js"></script>
        <!-- button enhancer library -->
        <script src="../js/bootstrap-button.js"></script>
        <!-- accordion library (optional, not used in demo) -->
        <script src="../js/bootstrap-collapse.js"></script>
        <!-- carousel slideshow library (optional, not used in demo) -->
        <script src="../js/bootstrap-carousel.js"></script>
        <!-- autocomplete library -->
        <script src="../js/bootstrap-typeahead.js"></script>
        <!-- tour library -->
        <script src="../js/bootstrap-tour.js"></script>
        <!-- library for cookie management -->
        <script src="../js/jquery.cookie.js"></script>
        <!-- calander plugin -->
        <script src="../js/fullcalendar.min.js"></script>
        <!-- data table plugin -->
        <script src="../js/jquery.dataTables.min.js"></script>

        <!-- chart libraries start -->
        <script src="../js/excanvas.js"></script>
        <script src="../js/jquery.flot.min.js"></script>
        <script src="../js/jquery.flot.pie.min.js"></script>
        <script src="../js/jquery.flot.stack.js"></script>
        <script src="../js/jquery.flot.resize.min.js"></script>
        <!-- chart libraries end -->

        <!-- select or dropdown enhancer -->
        <script src="../js/jquery.chosen.min.js"></script>
        <!-- checkbox, radio, and file input styler -->
        <script src="../js/jquery.uniform.min.js"></script>
        <!-- plugin for gallery image view -->
        <script src="../js/jquery.colorbox.min.js"></script>
        <!-- rich text editor library -->
        <script src="../js/jquery.cleditor.min.js"></script>
        <!-- notification plugin -->
        <script src="../js/jquery.noty.js"></script>
        <!-- file manager library -->
        <script src="../js/jquery.elfinder.min.js"></script>
        <!-- star rating plugin -->
        <script src="../js/jquery.raty.min.js"></script>
        <!-- for iOS style toggle switch -->
        <script src="../js/jquery.iphone.toggle.js"></script>
        <!-- autogrowing textarea plugin -->
        <script src="../js/jquery.autogrow-textarea.js"></script>
        <!-- multiple file upload plugin -->
        <script src="../js/jquery.uploadify-3.1.min.js"></script>
        <!-- history.js for cross-browser state change on ajax -->
        <script src="../js/jquery.history.js"></script>
        <!-- application script for Charisma demo -->
        <script src="../js/charisma.js"></script>


    </body>
</html>
';
        $file_name = $_SESSION["username"] . '_' . time() . '_exportFilterOrderDetailToHtml.html';
        $file = '../download/' . $file_name;
        // chmod($file, 0777);
        $export = file_put_contents($file, $html);
        $core->saveLogFileExportHTML($file_name);
    }

    echo json_encode(array('type' => 0, 'link' => 'download/' . $file_name));
    die;
}
?>